package com.kjc.demo.basic.controller;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.kjc.demo.basic.config.FTPConfig;
import com.kjc.demo.basic.config.YmlConfig;

import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping(value = "/test")
@Slf4j
public class TestYmlConfigController {

	@Autowired
	private YmlConfig ymlConfig;

	@Autowired
	private FTPConfig ftpConfig;
	
	/**
	 * 读取yml文件里配置
	 * */
	@GetMapping("/config")
	public String config(HttpServletRequest request) {
		String username = ymlConfig.getContractConfig().get("username");
		log.info(username);
		String host = ftpConfig.getCcab().getHost();
		log.info(host);
		return "success" + username + "--" + host;
	}
	
	
	/**
	 * 读取resources下面文件
	 * */
	@GetMapping("/property")
	public String property(HttpServletRequest request) {
		Properties prop = new Properties();
		InputStream inputstream = null;
		try {
			inputstream = Thread.currentThread().getContextClassLoader().getResourceAsStream("hlwzf/sdk.properties");
//			fileInputStream = new FileInputStream("F:\\code\\acp_sdk_800022000050072.properties");
			prop.load(inputstream);
			inputstream.close();
		} catch (IOException e) {

		}
		String tempPath = String.valueOf(prop.get("tempPath"));
		return "success" + "--" + tempPath;
	}

}
